import { View, Text, Button, Image } from "@tarojs/components";

import './index.less'
import BookBar from "@/components/BookBar";
import HistoryBar from "@/components/HistoryBar";
import { fetchNewsBookList } from "@/api/book";
import { useEffect, useState } from "react";

const bookIndex = require('../../data/detail_400000.json')
const bookList = require('../../data/books_1500000.json')

const Book = () => {
  console.log(bookIndex, 'bookIndex')
  const [newBookList,setNewBookList] = useState<any[]>([])

  const getNewsBook = async () => {
    const res = await fetchNewsBookList()
    setNewBookList(res?.data)

    console.log(res,'getNewsBook')

  }

  useEffect(() => {
    getNewsBook()
  },[])
  return (
    <View className="wrapper">

      <View className="title"> 热门推荐 </View>
      <HistoryBar bookList={bookList}></HistoryBar>

      <View className="title">新书上架</View>
      {
        newBookList.map(item => <BookBar key={item.name} {...item} item={item}></BookBar>)
      }
    </View>
  );
};

export default Book;
